package com.epoch.client.view;



import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ChooseGroup extends JFrame{
    JTextField txtID;
    JLabel labID;
    JButton butDoit;

    public ChooseGroup(String username) {

        JFrame frame = new JFrame("选择群聊ID");
        frame.setIconImage((new ImageIcon(this.getClass().getResource("/imgs/login_title.png"))).getImage());
        frame.setLayout(null);
        frame.getContentPane().setBackground(new Color(193,210,240));
        labID = new JLabel("加入的群聊");
        labID.setFont(new Font("华文行楷",0,15));
        labID.setBounds(45,50,90,30);
        frame.add(labID);

        txtID = new JTextField();
        txtID.setBounds(155,50,200,30);
        frame.add(txtID);

        butDoit = new JButton("进 入");
        butDoit.setBounds(155,100,100,50);
        butDoit.setBackground(new Color(180,220,230));
        frame.add(butDoit);

        frame.setBounds(568,307,400,250);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.setVisible(true);

        this.setSize(300, 150);

        butDoit.addActionListener((actionEvent) -> {
            String text = txtID.getText();
            Integer groupId = Integer.parseInt(text);
            frame.dispose();
            ChatFrame chatFrame = new ChatFrame(groupId, username);
            Thread t = new Thread(chatFrame);
            t.start();
        });
    }
}